/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modsimfv;

import fvm.FVModel;
import fvm.FVModelData;
import gui.GWS_GUI;
import gui.surfaceplot.Surface_GUI;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import listener.ParentEventListener;

/**
 *
 * @author max
 */
public class ModSimFV implements ParentEventListener{


    Thread Thread_GUI;
    Thread Thread_FVM;
    GWS_GUI gui;
    FVModel fvmodel;
    FVModelData fvmd;

    

    public ModSimFV() {
        
        

        Thread_GUI = new Thread(new Runnable() {

            @Override
            public void run() {

               
                gui = new GWS_GUI();
                gui.setVisible(true);
            }
        });

        Thread_FVM = new Thread(new Runnable() {

            @Override
            public void run() {
                
                fvmodel = new FVModel();
            
            }
        });
        
        

        Thread_FVM.start();
        Thread_GUI.start();
        try {
            Thread_FVM.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(ModSimFV.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            Thread_GUI.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(ModSimFV.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    
        
        gui.addParentEventListener((ParentEventListener)this);
       
        fvmodel.addParentEventListener((ParentEventListener)this);
       

        

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {


        ModSimFV modsimfv = new ModSimFV();

    }

    
    

    @Override
    public void Event_ModelCreated(FVModelData fvmd) {
            
            this.fvmd = fvmd;
            fvmodel.addModelData(fvmd);
            gui.paintModel(fvmd);
            gui.ModelisCreated();
          
            
            gui.repaint();
        
    }

    @Override
    public void Event_Assemble() {
        
        
        fvmodel.assemble();
        
    }

    @Override
    public void Event_Assembled() {
        
        gui.enableSim();
        gui.repaint();
        
    }

    @Override
    public void Event_StartSim(double t, double dt) {
        
        fvmodel.StartSim(t, dt);
       
    }

    @Override
    public void Event_Sim_finished(ArrayList<Vector> ht, double lowerb, double upperb, int timesteps) {
       
       gui.getColorBar().setulBound(lowerb, upperb);
       gui.setTimeSteps(timesteps);
       gui.setTimeStep(timesteps);
       gui.enableSurf();
       gui.enableAqui();
       gui.setplotqvisible(true);
        
        
gui.repaint();
    }

    @Override
    public void Event_getGUILocation() {
        fvmodel.setLocation(gui.getLocation(),gui.getSize());
    }

    @Override
    public void Event_plotSurface() {

        Surface_GUI surfgui = new Surface_GUI();
        surfgui.setModel(fvmodel, fvmd);
    }

    @Override
    public void Event_ProgBarVisible(boolean bool) {
        gui.setprogbarvisible(bool);
    }

    @Override
    public void Event_ProgBarRange(int u, int o) {
        gui.setprogbarrange(u, o);
    }

    @Override
    public void Event_ProgBarValue(int n) {
        gui.setprogbar(n);
    }

    @Override
    public void Event_NorthBound(ArrayList<Integer> typs, ArrayList<Double> vals) {
     
        fvmodel.setnorthbound(typs,vals);
        
    }
    public void Event_SouthBound(ArrayList<Integer> typs, ArrayList<Double> vals) {
     
        fvmodel.setsouthbound(typs,vals);
        
    }
    public void Event_EastBound(ArrayList<Integer> typs, ArrayList<Double> vals) {
     
        fvmodel.seteastbound(typs,vals);
        
    }
    public void Event_WestBound(ArrayList<Integer> typs, ArrayList<Double> vals) {
     
        fvmodel.setwestbound(typs,vals);
        
    }

  

   
    
    
  
}
